package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.Discuss;
import com.sk.bilibili.dto.DiscussInfo;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.DiscussService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
* @author 邵康
* @date 2021/11/25 10:15
*/
@CrossOrigin
@RestController
@RequestMapping("/discuss")
@Api(tags = "评论")
public class DiscussController {

    @Autowired
    private DiscussService discussService;

    @ApiOperation("添加评论：评论类型，对应的id，评论内容必须")
    @PostMapping("/add")
    public R<Discuss> add(@RequestBody Discuss discuss){
        return discussService.add(discuss);
    }

    @ApiOperation("获取评论：评论类型，对应的id必须  分页可以使用默认值")
    @PostMapping("/getDiscuss")
    public R<IPage<Discuss>> getDiscuss(@RequestBody DiscussInfo discussInfo){
        return discussService.getDiscuss(discussInfo);
    }

    @ApiOperation("递归删除评论")
    @GetMapping("/delete")
    public R<Void> delete(Integer id){
        return discussService.delete(id);
    }

    @ApiOperation("update")
    @PostMapping("/update")
    public R<Void> update(@RequestBody Discuss discuss){
        return discussService.update(discuss);
    }

    @ApiOperation("pageSearch")
    @GetMapping("/page")
    public R<IPage<Discuss>> page(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer size){
        return discussService.page(page,size);
    }

}
